package cas.ihep.util;

import javax.script.Bindings;
import java.util.HashMap;
import java.util.Map;

public class MapBindings extends HashMap<String,Object> implements Bindings {
    public MapBindings(Map<String,Object> other){
        super(other);
    }
    public MapBindings(){
        super();
    }

    public String getString(String key){
        Object ret=get(key);
        if(ret!=null && ret instanceof String){
            return (String)ret;
        }
        throw new RuntimeException("No such key or value");
    }

    public String getString(String key,String defaultValue){
        Object ret=get(key);
        if(ret!=null && ret instanceof String){
            return (String)ret;
        }
        return defaultValue;
    }
}
